﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YasharEl.Infrastructure.Core.EntityModel.Prototype
{
    public class DecimalValueConverter : AbstractDataTypeValueConverter
    {
        public override object UnwrapRealValue(object value)
        {
            if (value == null)
                return null;
            if (value is decimal)
                return value;
            if ((value is string) && string.IsNullOrEmpty(value as string))
                return null;

            return decimal.Parse(value.ToString());
        }

        public override string WrapValue(object value)
        {
            if (value == null)
                return null;
            if (value is string)
            {
                if (string.IsNullOrEmpty((value as string)))
                    return null;
            }

            return Convert.ToString(Convert.ToDecimal(value));
        }

        public override bool HasValue(object value)
        {
            if (value == null)
                return false;
            if (value is string)
            {
                if (string.IsNullOrEmpty((value as string)))
                    return false;
            }

            return true;
        }
    }
}
